﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 投稿列表
	/// </summary>
	[Serializable]
    public class Style : IEntity
	{
        public Style()
        {
            this.Tasks = new List<Task>();
        }
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set; get; }
		/// <summary>
		/// 名称
		/// </summary>
        public virtual string Name { set; get; }
        /// <summary>
        /// 描述
        /// </summary>
        public virtual string Content { get; set; }
        public virtual IList<Task> Tasks { get; set; }

        public static MappingConfiguration<Style> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<Style>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.Name,
                t.Content
            }).ToTable("Styles");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.Tasks).WithOpposite(d => d.Styles).MapJoinTable("TaskStyles",
                (t, d) => 
                    new 
                    {
                        TaskId = d.ID,
                        StyleId = t.ID
                    }
                );
            //threadMapping.HasAssociation(t => t.Login).WithOpposite(t=>t.ProductOrder).HasConstraint((p, l) => p.LoginID == l.ID);
            //threadMapping.HasAssociation(t => t.Forum).WithOpposite(f => f.Threads).HasConstraint((t, f) => t.ForumId == f.Id);
            //threadMapping.HasAssociation(t => t.User).WithOpposite(u => u.Threads).HasConstraint((t, u) => t.UserId == u.Id);

            return threadMapping;
        }

	}
}

